module.exports = function (gulp, plugins, options) {
  const fs = require('fs')
  const mergeStream = require('merge-stream')
  return function (done) {
    var arr = []
    var folder = []
    fs.readdirSync('src/static/images/sprite/').map(item => {
      var stat = fs.statSync(`src/static/images/sprite/${item}`)
      if (stat.isDirectory()) {
        folder.push(item)
      }
    })
    if (folder.length) {
      folder.map(item => {
        arr.push(
          gulp
          .src(`src/static/images/sprite/${item}/*.png`)
          .pipe(plugins.plumber())
          .pipe(
            plugins.spritesmith({
              imgName: `${item}.png`,
              cssName: `_${item}.scss`,
              imgPath: `../images/sprite/${item}.png`,
              cssTemplate: 'scss.template.handlebars',
              cssSpritesheetName: `${item}`
            })
          )
          .pipe(gulp.dest('src/static/images/sprite/'))
        )
      })
      return mergeStream(...arr)
    } else {
      done()
    }
  };
};